Repository navigation
[MRG] Fix batched GW/FGW envelope gradients with respect to marginals - #927
Open
xihaian251 wants to merge 1 commit into
Open
xihaian251 wants to merge 1 commit into
xihaian251 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #927 +/- ##
==========================================
+ Coverage 97.09% 97.11% +0.02%
==========================================
Files 130 130
Lines 27229 27464 +235
==========================================
+ Hits 26437 26673 +236
+ Misses 792 791 -1 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
Motivation and context
solve_gromov_batch(..., grad="envelope")detaches the transport plan but keeps a differentiable path toM,Ca,Cbonres.value;res.value_linearkeeps only its path toM. The marginalsa,bonly enter through the detached solver, sores.valuehad no gradient path to them, for both plain GW and fused GW.Independent 2×2 oracles (Wolfram quadruple-sum derivation + separate NumPy implementation): pure GW optimum
G*=18/25with∂G/∂p=−14/5,∂G/∂q=−8/5; fused GW (M=diag(3,3),α=1/2) optimumF*=51/100with∂F/∂p=−29/10,∂F/∂q=−23/10. On unmodified master withreg=0.1, the solver reachesvalue=0.72(marginal residual3.7e-14) yetgrad_p=grad_q=None;grad_M=(1−α)T*is already correct. Ten new tests fail on master and pass with the fix.How has this been tested
reg(u+v)−M_k = reg(log T_new − log T_prev)is proved from KKT.tol=1e-2yields the exactvalue=0.72,converged=True, marginal residual2e-14, but a wrong gradient (−2.75084vs−2.8). The gate now also requires marginal feasibility and stability of the centred sensitivities under one extra proximal projection; the counterexample is rejected.u→u+c,v→v−c. A wrap adding+250/−250to all returned potentials leaves gate flags, gradients and value unchanged (gradient diff ≤2e-15); the loose-tol counterexample stays rejected.grad="envelope". Measured call counts: Torch envelope 4, Torch detach/autodiff 3, NumPy all modes 3 — all non-target paths keep the original cost. Diagnostics (marginal_feasible,potentials_stable) are evaluated only on the Torch envelope marginal path and areNone(not evaluated) elsewhere.POT_BACKEND_DISABLE_PYTORCH=1checked.pytest -q test/batch/: 134 passed. Ten new tests fail on master. WithPOT_BACKEND_DISABLE_PYTORCH=1, the target test file gives 30 passed / 14 skipped. Ruff 0.5.2,git diff --checkclean. Full suite not run here; two pre-existing local environment limitations (BSP native-extension ABI mismatch, sandbox-blocked compiler probe) are documented, not claimed as passing.Scope
Local to
ot/batch/_quadratic.py, PyTorch only, first-order. Cost gradients and all forward values/plans are unchanged. The centred marginal gradient is registered only when the outer solve converged, the plan is marginally feasible, and the centred sensitivities are stable under one extra projection; the three checks are exposed inres.logand reduced over the whole batch. The stability check is an empirically validated criterion, not a mathematical guarantee for every GW problem. JAX/TensorFlow batch marginal gradients, higher-order differentiation, and unique sensitivities at active-set switching points are out of scope.PR checklist
graddocstring) and RELEASES.md updated with precise limitations.